package common;

import Dao.BlogDao;
import Dao.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Util {
    public static User  checkLoginStatus(HttpServletRequest req){
        // 判断是否登录了. 如果能够拿到 Session, 并且拿到 Session 里的 user对象,就认为是登录状态
        HttpSession session = req.getSession(false);
        if(session == null){
            // 此时还未登录.
            return null;
        }
        User user = (User) session.getAttribute("user");
        if(user == null){
            // 此时还未登录.
            return null;
        }
        return user;
    }

    public int getTotalTitle(int userId){
        BlogDao blogDao = new BlogDao();
        return blogDao.selectTotal(userId);
    }
}
